package uk.co.nazz.f21mc_a2.utils;

import java.util.HashMap;
import java.util.List;

import uk.co.nazz.f21mc_a2.diary.Attendee;
import android.content.Context;
import android.util.Log;
import android.widget.ArrayAdapter;

/**
 * Adapter for attendees ListView in display/edit activities
 * 
 * @author Andrew Stokes
 * 
 */
public class AttendeesAdapter extends ArrayAdapter<Attendee> {

	HashMap<String, Integer> map = new HashMap<String, Integer>();

	public AttendeesAdapter(Context context, int textViewId,
			List<Attendee> attendees) {
		super(context, textViewId, attendees);
		for (int i = 0; i < attendees.size(); ++i) {
			map.put(attendees.get(i).getName(), i);
			Log.v("F21MC_2", "map.put(" + i + ")");
		}

	}

	@Override
	public long getItemId(int position) {
		long itemId = -1;
		try {
			Attendee item = getItem(position);
			if (map.get(item) != null) {
				itemId = map.get(item);
				Log.v("F21MC_2", "map.get(" + item.getId() + ")");
			}
		} catch (Exception e) {
			Log.v("F21MC_2", e.getMessage());
		}

		return itemId;
	}

	@Override
	public boolean hasStableIds() {
		return true;
	}

}